/**
 * @param {number[]} nums
 * @return {number[]}
 */
 var maxScoreIndices = function(nums) {
  const n = nums.length
  const zero = new Array(n+1).fill(0), one = new Array(n+1).fill(0)
  for(let i = 1; i<=n; i++){
    if(nums[i-1] === 0){
      zero[i] = zero[i-1] + 1
    }else{
      zero[i] = zero[i-1]
    }
    one[i] = one[i-1] + nums[i-1]
  }
  let map = new Map(), max = -Infinity
  for(let i = 0; i<=n; i++){
    let left = zero[i], right = one[n] - one[i]
    map.set(i, left+right)
    max = Math.max(max, left+right)
  }
  let ans = []
  for(let [k, v] of map){
    if(v === max) ans.push(k)
  }
  return ans
};